package org.manager.units;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Projections;
import org.manager.generic.Repository.GenericHibernateRepository;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Repository;

/**
 * 科室DAO
 * 
 * @author zxf_noimp
 * 
 */
@SuppressWarnings("unchecked")
@Repository("classHoursRepository")
public class ClassHoursRepositoryImpl extends
		GenericHibernateRepository<ClassHours> implements ClassHoursRepository {

	public List<ClassHours> findPageClassHours(final ClassHours classHours,
			final int start, final int limit){
		List list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
				public Object doInHibernate(Session session) throws SQLException,HibernateException{
					return session.createCriteria(ClassHours.class)
						.add(Example.create(classHours))
						.setFirstResult(start)
						.setMaxResults(limit)
						.list();
				}
			}
		);
		return list;
	}

	public int totalRecord(final ClassHours classHours){
		return (Integer)getHibernateTemplate().execute(new HibernateCallback(){
			public Object doInHibernate(Session session) throws SQLException,HibernateException{
				return session.createCriteria(ClassHours.class)
					.add(Example.create(classHours))
					.setProjection(Projections.rowCount())
					.uniqueResult();
			}
		});
	}
}
